<?php

namespace app\api\controller;

class Hosparticle
{
    public $pagesize = 10;

    /**
     * 获取详情接口
     * @return \think\response\Json
     */
    public function info()
    {

        $id = trim(input("request.id"));//文章ID
        if (empty($id)) {
            $return = ['err' => 2, 'msg' => '参数错误', 'devMsg' => '获取失败，参数错误[id]'];
            return json($return);
        }
        $model = new  \app\admin\model\HospArticle();
        $info = $model->getDataForWhere(array('id' => $id));
        if (empty($info)) {
            $return = ['err' => 2, 'msg' => '信息不存在', 'devMsg' => ''];
            return json($return);
        }
        $info['ctimeFormat'] = date("Y-m-d H:i:s", $info['ctime']);

        $relationProductList = array();
        if ($info['relation_ids']) {
            $relationProductList = getProductListForIds($info['relation_ids'], 1, "*");
        }
        $info['relationProductLists'] = $relationProductList;
        $info['UserInfo'] = getUserInfoForID($info['uid']);
        $return = ['err' => 0, 'msg' => '获取成功', 'devMsg' => '获取成功', 'data' => $info];
        return json($return);
    }


    public function lists()
    {


        $bigtype = trim(input("request.bigtype"));//
        $pagesize = trim(input("request.pagesize"));//
        if (empty($bigtype)) {
            $bigtype = 1;
        }
        if (!empty($pagesize)) {
            $this->pagesize = $pagesize;
        }
        $DevModel = new \app\admin\model\HospArticle();
        $lists = $DevModel->lists(array('stats' => 0, 'is_delete' => 0, 'bigtype' => $bigtype), $this->pagesize, "*");

        foreach ($lists['data'] as $key => $val) {
            $lists['data'][$key]['ctimeFormat'] = date("Y-m-d H:i:s", $val['ctime']);
        }
        $lists['data'] =  changeUidToUserinfoForLists($lists['data'],'uid');

        $return['err'] = 0;
        $return['msg'] = '操作成功';
        $return['data'] = $lists;
        return json($return);

    }

}
